package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.*;
import com.atguigu.gmall.product.service.ManageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 里
 */
@RestController
@RequestMapping("/admin/product/")
public class ManageController {
    //控制器调用服务层
    @Autowired
    private ManageService manageService;

    // 获取一级分类数据
    @GetMapping("getCategory1")
    public Result getCategory1(){
        //获取所有的一级分类数据
        List<BaseCategory1> baseCategory1List = manageService.getBaseCategory1();
        // 把数据返回
        return Result.ok(baseCategory1List);
    }

    // 根据一级分类id获取二级分类数据
    @GetMapping("getCategory2/{category1Id}")
    public Result getCategory2(@PathVariable Long category1Id){
        //调用服务层方法获取数据
        List<BaseCategory2> baseCategory2List  =  manageService.getBaseCategory2(category1Id);
        // 把数据返回
        return Result.ok(baseCategory2List);
    }

    // 根据二级分类id获取三级分类数据
    @GetMapping("getCategory3/{category2Id}")
    public Result getCategory3(@PathVariable Long category2Id){
        //调用服务层方法获取数据
        List<BaseCategory3> baseCategory3List  =  manageService.getBaseCategory3(category2Id);
        // 把数据返回
        return Result.ok(baseCategory3List);
    }

    //根据分类id获取平台属性集合数据
    @GetMapping("attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result attrInfoList(@PathVariable Long category1Id,
                               @PathVariable Long category2Id,
                               @PathVariable Long category3Id){
        //调用服务层方法获取数据
        List<BaseAttrInfo> baseAttrInfoList = manageService.getAttrInfoList(category1Id,category2Id,category3Id);
        // 把数据返回
        return Result.ok(baseAttrInfoList);
    }

    // 保存平台属性
    @PostMapping("saveAttrInfo")
    public Result saveAttrInfo(@RequestBody BaseAttrInfo baseAttrInfo){
        //保存数据
        manageService.saveAttrInfo(baseAttrInfo);
        return  Result.ok();
    }

    //根据属性id 获取平台属性值数据集合
    @GetMapping("/getAttrValueList/{attrId}")
    public Result getAttrValueList(@PathVariable long attrId){
        // 回显平台属性值数据内容
        BaseAttrInfo baseAttrInfo =  manageService.getBaseAttrInfo(attrId);
      // List<BaseAttrValue> baseAttrValueList =  manageService.getAttrValueList(attrId);
       return Result.ok(baseAttrInfo.getAttrValueList());
    }
}
